package com.guigu.yh.springcloud.controller;

import com.guigu.yh.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 付款控制器
 *
 * @author 张颖辉（zyh）
 * @version 1.0.0
 * @date 2022/08/22
 */
@Slf4j
@RestController
public class PaymentController {
    @Resource
    private PaymentService paymentService;
    @Value("$server.port")
    private String serverPort;

    /**
     * 正常访问 ok 的方法
     *
     * @param id id
     * @return {@link String }
     * @author 张颖辉（zyh）
     * @date 2022/08/22
     * @version 1.0.0
     */
    @RequestMapping("hystrix/ok/{id}")
    public String paymentInfo_OK(@PathVariable("id") Integer id) {
        String result = paymentService.paymentInfo_OK(id);
        log.info("******** result：" + result);
        return result;
    }

    /**
     * 异常的方法：超时
     *
     * @param id id
     * @return {@link String }
     * @author 张颖辉（zyh）
     * @date 2022/08/22
     * @version 1.0.0
     */
    @RequestMapping("hystrix/timeout/{id}")
    public String paymentInfo_TimeOut(@PathVariable("id") Integer id) {
        String result = paymentService.paymentInfo_TimeOut(id);
        log.info("******** result：" + result);
        return result;
    }

    /**
     * 异常的方法：报错
     *
     * @param id id
     * @return {@link String }
     * @author 张颖辉（zyh）
     * @date 2022/08/22
     * @version 1.0.0
     */
    @RequestMapping("hystrix/err/{id}")
    public String paymentInfo_Err(@PathVariable("id") Integer id) {
        String result = paymentService.paymentInfo_Err(id);
        log.info("******** result：" + result);
        return result;
    }

    /**
     * 付款断路器
     * 服务断路演示，传整数正确，负数则报错
     *
     * @param id id
     * @return {@link String }
     * @author zyh
     * @date 2022/09/01
     * @version 1.0.0
     */
    @RequestMapping("hystrix/circuit/{id}")
    public String uitBreaker(@PathVariable("id") Integer id) {
        String result = paymentService.paymentCircuitBreaker(id);
        log.info("******** result：" + result);
        return result;
    }

}
